<!doctype html>
<html lang="en">

	<head>
		<meta charset="utf-8">

		<title>reveal.js – The HTML Presentation Framework</title>

		<meta name="description" content="A framework for easily creating beautiful presentations using HTML">
		<meta name="author" content="Hakim El Hattab">

		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">

		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

		<link rel="stylesheet" href="css/reveal.css">
		<link rel="stylesheet" href="css/theme/white.css" id="theme">
		<link rel="stylesheet" href="css/reveal-override.css"/>

		<!-- Theme used for syntax highlighting of code -->
		<link rel="stylesheet" href="lib/css/zenburn.css">

		<!-- Printing and PDF exports -->
		<script>
			var link = document.createElement( 'link' );
			link.rel = 'stylesheet';
			link.type = 'text/css';
			link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
			document.getElementsByTagName( 'head' )[0].appendChild( link );
		</script>

		<!--[if lt IE 9]>
		<script src="lib/js/html5shiv.js"></script>
		<![endif]-->
	</head>

	<body>

		<div class="reveal">

			<!-- Any section element inside of this container is displayed as a slide -->
			<div class="slides">


                <!-- Slides are separated by three dashes (quick 'n dirty regular expression) -->
                <!---
 ![](images/In28MinutesLogo-300X50.png)
 JavaEE_Model1_Architecture
JavaEE_Model2_Architecture
JavaEE_Model2_Architecture_Front_Controller
JavaEETypicalArchitecture
SpringModules 
 -->
                <section data-markdown data-separator="---">
                    <script type="text/template">

# Exception Handling
---
# Remember
> Good and Bad programmers cause Exceptions
---
# Two Keys
- Friendly message to end user
- Enough information to Debug the problem
---
# Puzzle

```java
//Will finally be executed in the program below?
  private static void method2() {
    Connection connection = new Connection();
    connection.open();
    try {
      //LOGIC
      String str = null;
      str.toString();
      return;
    } catch (Exception e) {
    } finally {
      connection.close();     
    }
  }
```
---
# Puzzle

> When is code in finally not executed?---
# Puzzle

```java
//Will code compile
  private static void method2() {
    Connection connection = new Connection();
    connection.open();
    try {
      //LOGIC
      String str = null;
      str.toString();
      return;
    } finally {
      connection.close();     
    }
  }
```
---
# Puzzle

```java
//Will code compile
  private static void method2() {
    Connection connection = new Connection();
    connection.open();
    try {
      //LOGIC
      String str = null;
      str.toString();
      return;
    } 
  }
```
---
# Exception Hierarchy
```java
//Pre-defined Java Classes
class Error extends Throwable{}
class Exception extends Throwable{}
class InterruptedException extends Exception{}
class RuntimeException extends Exception{}
class NullPointerException extends RuntimeException{}
```
---
# Custom Exceptions
```java
class CheckedException1 extends Exception{}
class CheckedException2 extends CheckedException1{}
class UnCheckedException extends RuntimeException{} 
class UnCheckedException2 extends UnCheckedException{}
```
---
# Puzzles Set 2
---
# Puzzles
```
    try {
      AmountAdder.addAmounts(new Amount("RUPEE", 5),
          new Amount("RUPEE", 5));
      String string = null;
      string.toString();
    } catch (CurrenciesDoNotMatchException e) {
      System.out
          .println("Handled CurrenciesDoNotMatchException");
    }
```
---
# Puzzles
```
    try {
      AmountAdder.addAmounts(new Amount("RUPEE", 5),
          new Amount("USD", 5));
      String string = null;
      string.toString();
    } catch (Exception e) {
      System.out
          .println("Handled Exception");
    } catch (CurrenciesDoNotMatchException e) {
      System.out
          .println("Handled CurrenciesDoNotMatchException");
    }
```
---
# Puzzles
```
    try {
      //code
    }  catch (IOException | SQLException ex ) {
      ex.printStackTrace();
    }
```
---
## Exception Handling Best Practices
- Never Hide Exceptions
- Do not use it for flow control
- Think about your user
- Think about your support team
- Think about the calling method
- Have global exception handling
---
# Thank You
---
                    </script>
                </section>

			</div>

		</div>

		<script src="lib/js/head.min.js"></script>
		<script src="js/reveal.js"></script>


		<script>

			// ![](images/NAME.png) More info https://github.com/hakimel/reveal.js#configuration
			Reveal.initialize({
				controls: false,
				progress: false,
				history: true,
				center: true,

				transition: 'slide', // none/fade/slide/convex/concave/zoom

				// More info https://github.com/hakimel/reveal.js#dependencies
				dependencies: [
					{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
					{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
					{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
					{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
					{ src: 'plugin/zoom-js/zoom.js', async: true },
					{ src: 'plugin/notes/notes.js', async: true }
				]
			});

		</script>

	</body>
</html>
